From: Carlos Garnacho Date: Tue, 5 Nov 2019 23:48:25 +0000 (+0100) Subject: screenshot: Allow saving to clipboard X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~781^2^2~449 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=cf6beee9e23b2445160b1aecf04df21ea7613ad7;p=gnome-shell.git screenshot: Allow saving to clipboard If no target file is specified (i.e. filename is an empty string), the screenshot will be stored on the clipboard instead. https://gitlab.gnome.org/GNOME/mutter/issues/789 https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/810 --- diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js index c50c4a363..11f8afa44 100644 --- a/js/ui/screenshot.js +++ b/js/ui/screenshot.js @@ -86,6 +86,9 @@ var ScreenshotService = class { } _createStream(filename) { + if (filename == '') + return [Gio.MemoryOutputStream.new_resizable(), null]; + if (GLib.path_is_absolute(filename)) { try { let file = Gio.File.new_for_path(filename); @@ -123,7 +126,15 @@ var ScreenshotService = class { stream.close(null); - let filenameUsed = file.get_path(); + let filenameUsed = ''; + if (file) { + filenameUsed = file.get_path(); + } else { + let bytes = stream.steal_as_bytes(); + let clipboard = St.Clipboard.get_default(); + clipboard.set_content(St.ClipboardType.CLIPBOARD, 'image/png', bytes); + } + let retval = GLib.Variant.new('(bs)', [result, filenameUsed]); invocation.return_value(retval); }